/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.google;

import acceso.hibernate.AQuery;
import wf.dto.georef.pfactpun;
import wf.dto.georef.pfactzon;
import wf.dto.georef.pfborpun;
import wf.dto.georef.pfborzon;
import wf.dto.georef.pflisare;
import wf.dto.georef.pflispun;
import wf.dto.georef.pfnuepun;
import wf.dto.georef.pfnuezon;
import acceso.hibernate.AccesoHibernate;
import acceso.util.Escritor;
import com.google.gson.Gson;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.StatelessSession;
import org.hibernate.Transaction;
import wf.dto.geoacr.PungeoDto;
import wf.dto.geoacr.ZongeoDto;

/**
 *
 * @author romulogalindo
 */
public class GoogleService extends HttpServlet {
    //private Query HQUERY;
    public void init() throws ServletException {
        super.init();
    }

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String r="";
        try {
            String que  = request.getParameter("xact");
            switch (que) {
                case "1":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            //PARAMETROS A UTILIZAR
                            String AREA = request.getParameter("area");
                            
                            java.util.List l = new ArrayList();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pflisare");
                            Escritor.escribe_frawor(HQUERY.getQueryString());
                            List l2 = HQUERY.list();
                            for(int i = 0 ; i < l2.size() ; i++){
                                pflisare area = (pflisare) l2.get(i);
                                l.add(new Areas(area.getId_zongeo(), area.getNo_zongeo()));
                            }
                            Gson g = new Gson();
                            out.print(g.toJson(l));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "2":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            String AREA = request.getParameter("area");
                            
                            pfnuezon nuevazona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfnuezon");
                            HQUERY.setString("p_no_zongeo", AREA);
                            HQUERY.setShort("p_ti_zongeo", Short.parseShort("1"));
                            nuevazona = (pfnuezon) HQUERY.uniqueResult();
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_no_zongeo", AREA).replaceAll(":p_ti_zongeo", "1"));
                            out.print(nuevazona.getPfnuezon());
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "3":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            String AREA = request.getParameter("area");
                            int ID = Integer.parseInt(request.getParameter("id"));
                            
                            pfactzon actzona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfactzon");
                            HQUERY.setInteger("p_id_zongeo", ID);
                            HQUERY.setString("p_no_zongeo", AREA);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_no_zongeo", AREA).replaceAll(":p_id_zongeo", ""+ID));
                            //int rpta = HQUERY.executeUpdate();
                            actzona = (pfactzon) HQUERY.uniqueResult();
                            
                            Escritor.escribe_frawor("--> Fin:");
                            out.print("1");
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "4":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int ID = Integer.parseInt(request.getParameter("id"));
                            
                            pfborzon borzona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfborzon");
                            HQUERY.setInteger("p_id_zongeo", ID);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_id_zongeo", ""+ID));
                            borzona = (pfborzon) HQUERY.uniqueResult();
                            
                            out.println("1");
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "5":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int ID_AREA = Integer.parseInt(request.getParameter("id_area"));
                            
                            java.util.List l = new ArrayList();
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pflispun");
                            HQUERY.setInteger("p_id_zongeo", ID_AREA);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_id_zongeo", ""+ID_AREA));
                            l= HQUERY.list();
                            Gson g = new Gson();
                            out.print(g.toJson(l));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "6":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int ID_AREA = Integer.parseInt(request.getParameter("id_area"));
                            BigDecimal bd_lat = new BigDecimal(request.getParameter("lat"));
                            BigDecimal bd_lon = new BigDecimal(request.getParameter("lon"));
                            
                            pfnuepun punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfnuepun");
                            HQUERY.setInteger("p_id_zongeo", ID_AREA);
                            HQUERY.setBigDecimal("p_nu_geolat", bd_lat);
                            HQUERY.setBigDecimal("p_nu_geolon", bd_lon);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_id_zongeo", ""+ID_AREA).replaceAll(":p_nu_geolat", ""+bd_lat).replaceAll(":p_nu_geolon", ""+bd_lon));
                            punto = (pfnuepun) HQUERY.uniqueResult();
                            
                            out.print(punto.getPfnuepun());
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "7":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int ID_AREA = Integer.parseInt(request.getParameter("id_area"));
                            int ID_PUNTO = Integer.parseInt(request.getParameter("id_punto"));
            
                            BigDecimal bd_lat_n = new BigDecimal(request.getParameter("va_lat"));
                            BigDecimal bd_lon_n = new BigDecimal(request.getParameter("va_lon"));

                            pfactpun punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfactpun");
                            HQUERY.setInteger("p_id_zongeo", ID_AREA);
                            HQUERY.setInteger("p_id_pungeo", ID_PUNTO);
                            HQUERY.setBigDecimal("p_nu_geolat", bd_lat_n);
                            HQUERY.setBigDecimal("p_nu_geolon", bd_lon_n);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_id_zongeo", ""+ID_AREA).replaceAll(":p_id_pungeo", ""+ID_PUNTO).replaceAll(":p_nu_geolat", ""+bd_lat_n).replaceAll(":p_nu_geolon", ""+bd_lon_n));
                            punto = (pfactpun) HQUERY.uniqueResult();
                            
                            out.println("1");
                        }catch(Exception ep){
                            Escritor.escribe_errors("E["+ep.getClass()+"]:"+ep.getMessage());
                            Escritor.escribe_errors("E["+((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "8":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int ID_AREA = Integer.parseInt(request.getParameter("id_area"));
                            int ID_PUNTO = Integer.parseInt(request.getParameter("id_punto"));
                            
                            
                            pfborpun punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfborpun");
                            HQUERY.setInteger("p_id_zongeo", ID_AREA);
                            HQUERY.setInteger("p_id_pungeo", ID_PUNTO);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_id_zongeo", ""+ID_AREA).replaceAll(":p_id_pungeo", ""+ID_PUNTO));
                            punto = (pfborpun) HQUERY.uniqueResult();
                            HSESSION.close();
                            
                            out.println("1");
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "9":
                    try{
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                        Query HQUERY=HSESSION.getNamedQuery("certic.Posgeoref");
                        Escritor.escribe_frawor("GOOGLESEZRVICE: " + HQUERY.getQueryString());
                        java.util.List objetos = HQUERY.list();
                        Gson g = new Gson();
                        out.println(g.toJson(objetos)); 
                    }catch(Exception ep){
                        Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                    }
                    break;
                case "10":
                    try{
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                        Query HQUERY = HSESSION.getNamedQuery("georef.pflispunare");
                        Escritor.escribe_frawor(HQUERY.getQueryString());
                        java.util.List ptos = HQUERY.list();
                        Gson g = new Gson();
                        out.println(g.toJson(ptos));
                    }catch(Exception ep){
                        Escritor.escribe_errors("Error al consultar:"+ep);
                    }
                    break;
                case "11":
                    try{
                        BigDecimal nu_geolat = new BigDecimal(request.getParameter("p_nu_geolat"));
                        BigDecimal nu_geolon = new BigDecimal(request.getParameter("p_nu_geolon"));
                        short nu_radmet =Short.parseShort(request.getParameter("p_nu_radmet"));
                        short ti_descri =Short.parseShort(request.getParameter("p_ti_descri"));
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
    //                    Query HQUERY=HSESSION.getNamedQuery("credit.Posgeoref2");
                        
                        AQuery IHQUERY = new AQuery(HSESSION.getNamedQuery("credit.Posgeoref2"));
                        
                        IHQUERY.setBigDecimal("p_nu_geolat", nu_geolat);
                        IHQUERY.setBigDecimal("p_nu_geolon", nu_geolon);
                        IHQUERY.setShort("p_nu_radmet", nu_radmet);
                        IHQUERY.setShort("p_ti_descri", ti_descri);
                        Escritor.escribe_frawor("GOOGLESERVICE: " + IHQUERY.getQuery());
                        java.util.List objetos = IHQUERY.getMquery().list();
                        Gson g = new Gson();
                        out.println(g.toJson(objetos)); 
                    }catch(Exception ep){
                        if(ep instanceof org.hibernate.exception.SQLGrammarException){
                            System.out.println(""+((org.hibernate.exception.SQLGrammarException)ep).getMessage());
                            System.out.println(""+((org.hibernate.exception.SQLGrammarException)ep).getLocalizedMessage());
                            System.out.println(""+((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
                            System.out.println(""+((org.hibernate.exception.SQLGrammarException)ep).getSQL());
                            System.out.println(""+((org.hibernate.exception.SQLGrammarException)ep).getSQLState());
                            ep.printStackTrace();
                        }
                        Escritor.escribe_errors("Error al consultar:"+ep.getMessage()+"::"+ep.getClass());
                    }
                    break;
                case "12":
                    {
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                        try {
                            Query HQUERY = HSESSION.getNamedQuery("georef.pfpunpelg");
                            Escritor.escribe_frawor(HQUERY.getQueryString());
                            java.util.List ptop = HQUERY.list();
                            Gson g = new Gson();
                            out.println(g.toJson(ptop));
                        } catch (Exception ep) {
                            Escritor.escribe_errors("Error al consultar:" + ep);
                        } finally {
                            close(HSESSION);
                        }
                        break;
                    }
                case "13":
                    {
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                        try {
                            Query HQUERY = HSESSION.getNamedQuery("georef.pflispuncir");
                            Escritor.escribe_frawor(HQUERY.getQueryString());
                            java.util.List ptop = HQUERY.list();
                            Gson g = new Gson();
                            out.println(g.toJson(ptop));
                        } catch (Exception ep) {
                            Escritor.escribe_errors("Error al consultar:" + ep);
                        } finally {
                            close(HSESSION);
                        }
                        break;
                    }
                case "100":
                    try{
                        Short p_ti_zongeo = Short.parseShort(request.getParameter("ti_zongeo"));
                        StatelessSession HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                        Query HQUERY = HSESSION.getNamedQuery("zongeo.pflispunare");
                        HQUERY.setShort("p_ti_zongeo", p_ti_zongeo);
                        Escritor.escribe_frawor(HQUERY.getQueryString());
                        java.util.List ptos = HQUERY.list();
                        Gson g = new Gson();
                        out.println(g.toJson(ptos));
                    }catch(Exception ep){
                        Escritor.escribe_errors("Error al consultar:"+ep+"\n"+ep.getClass());
                        if(ep instanceof org.hibernate.exception.SQLGrammarException){
                            Escritor.escribe_errors("[100]"+ ((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage() );
                            Escritor.escribe_errors("[100]"+((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getSQLState() );
                            
                        }
                    }
                    break;
                case "101":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            //PARAMETROS A UTILIZAR
                            String AREA = request.getParameter("area");
                            
                            java.util.List l = new ArrayList();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pflisare");
                            HQUERY.setShort("p_ti_zongeo", new Short("1"));
                            Escritor.escribe_frawor(HQUERY.getQueryString());
                            Gson g = new Gson();
                            out.print(g.toJson(HQUERY.list()));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "102":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            String no_zongeo = request.getParameter("no_zongeo");
                            Short ti_zongeo =  Short.parseShort(request.getParameter("ti_zongeo"));
                            Short ti_forgeo =  Short.parseShort(request.getParameter("ti_forgeo"));
                            String no_zondes = request.getParameter("no_zondes");
                            ZongeoDto nuevazona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfnuezon");
                            HQUERY.setString("p_no_zongeo", no_zongeo);
                            HQUERY.setShort("p_ti_zongeo", ti_zongeo);
                            HQUERY.setShort("p_ti_forgeo", ti_forgeo);
                            HQUERY.setString("p_no_zondes", no_zondes);
                            nuevazona = (ZongeoDto) HQUERY.uniqueResult();
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_no_zongeo", no_zongeo).replaceAll(":p_ti_zongeo", ""+ti_zongeo).replaceAll(":p_ti_forgeo", ""+ti_forgeo).replaceAll(":p_no_zondes", ""+no_zondes));
                            out.print(new Gson().toJson(nuevazona));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "103":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            String no_zongeo = request.getParameter("no_zongeo");
                            String no_zondes = request.getParameter("no_zondes");
                            
                            ZongeoDto actzona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfactzon");
                            HQUERY.setInteger("p_id_zongeo", co_zongeo);
                            HQUERY.setString("p_no_zongeo", no_zongeo);
                            HQUERY.setString("p_no_zondes", no_zondes);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_no_zongeo", no_zongeo).replaceAll(":p_id_zongeo", ""+co_zongeo).replaceAll(":p_no_zondes", no_zondes));
                            //int rpta = HQUERY.executeUpdate();
                            actzona = (ZongeoDto) HQUERY.uniqueResult();
                            
                            Escritor.escribe_frawor("--> Fin:");
                            out.print(new Gson().toJson(actzona));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "104":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            
                            pfborzon borzona = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfborzon");
                            HQUERY.setInteger("p_co_zongeo", co_zongeo);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_co_zongeo", ""+co_zongeo));
                            borzona = (pfborzon) HQUERY.uniqueResult();
                            
                            out.println("1");
                        }catch(Exception ep){
                            if(ep instanceof  org.hibernate.exception.SQLGrammarException){
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getMessage() );
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getSQLState());
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQL() );
                            }
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage()+":"+ep.getClass());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "105":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int p_co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            
                            java.util.List l = new ArrayList();
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pflispun");
                            HQUERY.setInteger("p_co_zongeo", p_co_zongeo);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_co_zongeo", ""+p_co_zongeo));
                            l= HQUERY.list();
                            Gson g = new Gson();
                            out.print(g.toJson(l));
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "106":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            BigDecimal nu_geolat = new BigDecimal(request.getParameter("nu_geolat"));
                            BigDecimal nu_geolon = new BigDecimal(request.getParameter("nu_geolon"));
                            
                            PungeoDto punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfnuepun");
                            HQUERY.setInteger("p_co_zongeo", co_zongeo);
                            HQUERY.setBigDecimal("p_nu_geolat", nu_geolat);
                            HQUERY.setBigDecimal("p_nu_geolon", nu_geolon);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_co_zongeo", ""+co_zongeo).replaceAll(":p_nu_geolat", ""+nu_geolat).replaceAll(":p_nu_geolon", ""+nu_geolon));
                            punto = (PungeoDto) HQUERY.uniqueResult();
                            
                            out.print(new Gson().toJson(punto));
                        }catch(Exception ep){
                            if(ep instanceof  org.hibernate.exception.SQLGrammarException){
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getMessage() );
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getSQLState());
                                System.out.println(""+  ((org.hibernate.exception.SQLGrammarException)ep).getSQL() );
                            }
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage()+":"+ep.getClass());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                case "107":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int p_co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            int p_co_pungeo = Integer.parseInt(request.getParameter("co_pungeo"));
            
                            BigDecimal p_nu_geolat = new BigDecimal(request.getParameter("nu_geolat"));
                            BigDecimal p_nu_geolon = new BigDecimal(request.getParameter("nu_geolon"));

                            PungeoDto punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfactpun");
                            HQUERY.setInteger("p_co_zongeo", p_co_zongeo);
                            HQUERY.setInteger("p_co_pungeo", p_co_pungeo);
                            HQUERY.setBigDecimal("p_nu_geolat", p_nu_geolat);
                            HQUERY.setBigDecimal("p_nu_geolon", p_nu_geolon);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_co_zongeo", ""+p_co_zongeo).replaceAll(":p_co_pungeo", ""+p_co_pungeo).replaceAll(":p_nu_geolat", ""+p_nu_geolat).replaceAll(":p_nu_geolon", ""+p_nu_geolon));
                            punto = (PungeoDto) HQUERY.uniqueResult();
                            
                            out.println(new Gson().toJson(punto));
                        }catch(Exception ep){
                            Escritor.escribe_errors("E["+ep.getClass()+"]:"+ep.getMessage());
                            Escritor.escribe_errors("E["+((org.hibernate.exception.SQLGrammarException)ep).getSQLException().getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
                    case "108":
                    {
                        StatelessSession HSESSION = null;
                        try{
                            //PARAMETROS A UTILIZAR
                            int co_zongeo = Integer.parseInt(request.getParameter("co_zongeo"));
                            int co_pungeo = Integer.parseInt(request.getParameter("co_pungeo"));
                            
                            
                            pfborpun punto = null;
                            HSESSION = AccesoHibernate.getSessionFactory().openStatelessSession();
                            Query HQUERY = HSESSION.getNamedQuery("zongeo.pfborpun");
                            HQUERY.setInteger("p_co_zongeo", co_zongeo);
                            HQUERY.setInteger("p_co_pungeo", co_pungeo);
                            Escritor.escribe_frawor(HQUERY.getQueryString().replaceAll(":p_co_zongeo", ""+co_zongeo).replaceAll(":p_co_pungeo", ""+co_pungeo));
                            punto = (pfborpun) HQUERY.uniqueResult();
                            HSESSION.close();
                            
                            out.println("1");
                        }catch(Exception ep){
                            Escritor.escribe_errors("Error al consultar:"+ep.getMessage());
                        }finally{
                            close(HSESSION);
                        }
                        break;
                    }
            }
        } finally {            
            out.close();
        }
    }

    public void close(StatelessSession HSESSION) {
        try {            
            if (HSESSION != null) {
                if(!HSESSION.connection().isClosed()) HSESSION.close();
            }
        }catch (Exception ep) {HSESSION = null;}
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
